Skip to content

Conversation

kuishou68
Copy link
Collaborator

@kuishou68 kuishou68 commented Sep 19, 2025

Summary

This PR introduces comprehensive Codex integration into AionUi, transforming the application into a unified platform supporting Gemini CLI, ACP backends, and Codex. The implementation includes a complete agent management system, message processing architecture, permission handling, and significant UX enhancements.

Major Features

🤖 Codex Integration (Core)

  • Full MCP Protocol Implementation: New CodexMcpConnection with JSON-RPC 2.0 communication
  • Agent Management System: CodexAgentManager with lifecycle management and conversation routing
  • Event Processing: Comprehensive event handling for sessions, tool calls, permissions, and status updates
  • Message Transformation: Streaming message processing with real-time UI updates

🛡️ Permission & Security System

  • Dynamic Permission Management: Tool-specific permission requests (bash, edit, read, write, web_search, etc.)
  • Persistent Storage: User permission preferences saved across sessions
  • Interactive UI Components: Permission approval dialogs with detailed information display
  • Always/Allow Once Options: Flexible permission granting with memory

🔧 Tool Execution & Display

  • Rich Tool Call UI: Specialized displays for exec commands, file patches, MCP tools, and web searches
  • Real-time Output: Streaming command execution with stdout/stderr/exit code display
  • Patch Visualization: Syntax-highlighted code diffs with apply/reject functionality
  • Duration Tracking: Accurate timing including nanoseconds for all tool executions

📁 Enhanced File Operations

  • Workspace Integration: Unified workspace supporting all agent types (Gemini/ACP/Codex)
  • Drag & Drop: Multi-file upload with automatic workspace path resolution
  • Paste Support: Image and file paste functionality in all chat contexts
  • Auto-refresh: Workspace tree updates automatically after file operations

🌐 Error Handling & Recovery

  • Structured Error System: Classified error types (network, authentication, protocol, timeout)
  • i18n Error Messages: Localized error descriptions across all supported languages
  • Retry Logic: Automatic recovery for transient failures
  • User-friendly Display: Clear error messages with actionable guidance

💬 UX Improvements

  • Thought Process Display: Streaming reasoning visualization with shimmer animation
  • Status Updates: Real-time task progress with contextual information
  • Multi-conversation Support: Independent Codex sessions per workspace
  • Loading States: Improved feedback during agent initialization and message processing

Architecture Changes

New Agent Layer Structure

src/agent/codex/
├── connection/
│   └── CodexMcpConnection.ts       (608 lines) - MCP protocol implementation
├── core/
│   ├── CodexMcpAgent.ts            (367 lines) - Main agent coordination
│   └── ErrorService.ts             (96 lines)  - Error classification
├── handlers/
│   ├── CodexEventHandler.ts        (253 lines) - Event processing
│   ├── CodexFileOperationHandler.ts(287 lines) - File operations
│   ├── CodexSessionManager.ts      (299 lines) - Session lifecycle
│   └── CodexToolHandlers.ts        (374 lines) - Tool call handling
└── messaging/
    ├── CodexMessageEmitter.ts      (20 lines)  - Event emission
    └── CodexMessageProcessor.ts    (176 lines) - Message transformation

Type System Enhancements

  • Event Types: 316 lines of comprehensive event type definitions
  • Permission Types: 74 lines of permission request/response types
  • Tool Types: 98 lines of tool call metadata types
  • Error Types: 38 lines of structured error definitions

Component Organization

  • Message Components: Refactored into acp/ and codex/ subfolders for better organization
  • Reusable Base Components: BasePermissionDisplay and BaseToolCallDisplay for shared UI patterns
  • Specialized Displays: Tool-specific components (ExecCommand, Patch, WebSearch, McpTool)

Technical Highlights

Message Flow Architecture

User Input → CodexSendBox → CodexAgentManager → CodexMcpConnection
           → CodexEventHandler → CodexMessageProcessor → UI Components

Streaming Response Handling

  • Real-time message accumulation and composition
  • Delta processing for partial content updates
  • Deduplication logic to prevent double messages
  • Proper handling of thinking process and reasoning steps

Workspace Management

  • Renamed GeminiWorkspace to ChatWorkspace for multi-agent support
  • Automatic workspace file tree refresh after Codex operations
  • File generation integration with workspace path resolution
  • Drag-and-drop support across all agent types

Configuration & Storage

  • New appConfig.ts for dynamic constants and Electron integration
  • Permission storage with tool-specific preferences
  • Shell execution state persistence in conversation history
  • Enhanced LocalStorage utilities for Codex settings

Internationalization

Complete i18n coverage for all new features:

  • 🇨🇳 Chinese (Simplified & Traditional)
  • 🇺🇸 English
  • 🇯🇵 Japanese

Translation additions: ~200+ new keys per language covering:

  • Permission request dialogs
  • Tool call displays
  • Error messages
  • Status updates
  • UI labels

Bug Fixes & Optimizations

Fixed Issues

  • ACP timeout issues with --sandbox flag removed
  • Shell execution state persistence in conversation history
  • Message duplication in Codex thinking process
  • Base64 decoding for command output chunks
  • Workspace file selection echo issues
  • Permission request duplication
  • File paste handling conflicts

Performance Improvements

  • Optimized message transformation with reduced type assertions
  • Efficient tool registry system replacing hardcoded names
  • Cleaned up debug logging (removed ~50+ console.log statements)
  • Improved loading states and UI responsiveness

Code Quality

  • Removed unsafe type assertions (replaced with proper type guards)
  • Modularized large files into focused components
  • Enhanced type safety throughout Codex implementation
  • Fixed ESLint warnings and TypeScript strict mode issues

Breaking Changes

  • GeminiWorkspace component renamed to ChatWorkspace
  • Message component structure reorganized (acp/codex subfolders)
  • IPC bridge extensions for Codex-specific methods

Migration Notes

  • No database migrations required
  • Permission settings stored in new format (backward compatible)
  • Workspace file paths remain unchanged

Testing

  • ✅ TypeScript compilation without errors
  • ✅ All agent types (Gemini/ACP/Codex) working correctly
  • ✅ Permission system tested across all tool types
  • ✅ File operations verified (read/write/patch/generate)
  • ✅ Multi-conversation support validated
  • ✅ Error handling tested with various failure scenarios
  • ✅ i18n verified across all supported languages

Stats

  • Files Changed: 93 files
  • Lines Added: 8,093
  • Lines Removed: 1,157
  • Net Addition: +6,936 lines
  • New Files: ~30+ new TypeScript modules
  • Refactored Components: ~15 major components

Version

Updated to v1.2.5

kuishou68 and others added 6 commits September 18, 2025 15:35
…p solution when the agent requests interception.
Resolved conflicts in:
- src/renderer/pages/conversation/gemini/GeminiWorkspace.tsx: Kept codex support in eventPrefix
- src/renderer/pages/guid/index.tsx: Merged logos imports (both CodexLogo and IflowLogo)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@aionui
Copy link
Contributor

aionui bot commented Sep 19, 2025

🤖 Hi @kuishou68, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

- Cleaned up extensive debug logging from CodexMcpConnection.ts
- Removed verbose console logs from CodexMcpAgent
- Simplified CodexAgentManager logging to essential error/warning only
- Fixed unused variable warnings in TypeScript
- Removed unused pauseReason property
- Fixed formatting and empty catch blocks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
kuishou68 and others added 4 commits September 19, 2025 16:01
…anager

- Added createContentMessage() in CodexAgentManager to handle content validation
- Moved content filtering logic from transformMessage to CodexAgentManager layer
- Simplified chatLib.ts transformMessage to assume pre-validated data
- Updated all content message creation points to use new validation
- Improved separation of concerns between common library and agent-specific logic

Benefits:
- chatLib.ts is now more generic and doesn't contain agent-specific logic
- Content validation happens at the appropriate layer (agent manager)
- Better maintainability and cleaner code architecture

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…essageToolGroup

- Added optimized agentType-based conversation handler selection
- Improved callId handling with toolCall.toolCallId fallback
- Added direct import of acpConversation and codexConversation
- Enhanced confirmation logic to avoid unnecessary API calls when agentType is available
- Removed unused display variable

Benefits:
- Better performance by avoiding extra conversation.get calls
- More robust callId handling for different agent types
- Unified permission handling logic in MessageToolGroup

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Replace hardcoded Chinese recovery actions in CodexAgentManager.ts with i18n keys
- Add recovery_actions object to all locale files for network error suggestions
- Internationalize ACP authentication error messages in guid/index.tsx
- Add console_error and failed_confirm keys to acp.auth section
- Fix TypeScript type errors with returnObjects option for array translations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Split 1,271-line CodexAgentManager into focused modules (83% reduction):
  - CodexAgentManager.ts (215 lines) - main controller following GeminiAgentManager pattern
  - CodexEventHandler.ts (173 lines) - unified event dispatcher
  - CodexMessageProcessor.ts (165 lines) - message flow handling
  - CodexToolHandlers.ts (251 lines) - tool execution handlers

- Centralize type definitions in src/common/codexTypes.ts:
  - Replace all 'any' types with discriminated unions for type safety
  - Add comprehensive interfaces for all event data types
  - Provide extensible base interfaces for future message format expansion

- Remove duplicate type definitions from original file
- Maintain API compatibility while improving maintainability
- Enable better IDE support with precise type inference

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@aionui
Copy link
Contributor

aionui bot commented Sep 19, 2025

🤖 Hi @kuishou68, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

…pe safety

- Refactor transformMessage to eliminate undefined returns for better type safety
- Move Codex-specific message handling logic from chatLib.ts to CodexEventHandler.ts
- Extract ExtendedAcpPermissionRequest interface to Codex module for better encapsulation
- Standardize message processing: content, user_content, error types in core chatLib
- Remove unused CodexAgentManagerOriginal.ts backup file
- Update CodexMessageProcessor to use standard content type instead of ai_content
- Improve error handling with explicit error messages for unsupported message types
zhoukai and others added 20 commits September 29, 2025 15:27
- Merge onNetworkError and onError callbacks into unified onError with rich error context
- Remove stream_error type from CodexEventMsg and update related processing
- Replace manual codex/event construction with direct error handling
- Simplify error processing flow: Connection → onError → MessageProcessor.processStreamError
- Maintain encapsulation by keeping messageProcessor private with getter method
- Add comprehensive error details (type, source, timeout info, retry counts)
- Remove redundant wrapper methods in CodexEventHandler
…type parsing error field elicitation/create
…red base components

Major refactoring to eliminate code duplication and improve maintainability:

Permission Components:
- Created BasePermissionDisplay for shared permission UI logic
- Refactored MessageCodexPermission as factory component using subtype discrimination
- Split into ExecApprovalDisplay and ApplyPatchApprovalDisplay with specialized rendering
- Fixed permission ID generation to use call_id for uniqueness
- Simplified CodexEventHandler logic by removing redundant data transformation

Tool Call Components:
- Created BaseToolCallDisplay for shared tool call UI structure
- Eliminated duplicate StatusTag definitions across 4 components
- Refactored ExecCommandDisplay, PatchDisplay, WebSearchDisplay, McpToolDisplay
- Reduced code by 25-40% per component while maintaining functionality

Type System Improvements:
- Updated event data types to match actual JSON-RPC logs
- Fixed FileChange union type to support both current and legacy formats
- Made PatchApprovalData fields accurately reflect required vs optional properties
- Removed unused utility functions from permissionUtils
…mponents

- Add translation keys for 4 languages (en-US, zh-CN, zh-TW, ja-JP)
- Replace hardcoded strings with t() function calls in Permission components
- Replace hardcoded strings with t() function calls in ToolCall components
- Fix titleKey translation handling in permission display components
- Support dynamic translation of status labels, action buttons, and tool details
…noseconds

- Calculate total duration as secs + nanos/1,000,000,000
- Display duration in ms for values < 1s, otherwise in seconds with 2 decimal places
- Update i18n labels to support dynamic unit formatting
- Fix issue where command execution time showed 0s instead of actual duration
…pport

- Fix React hooks usage in ErrorService class by removing useTranslation
- Remove unused context parameter from handleError method
- Add structured error message format with error codes in MessageProcessor
- Implement intelligent error translation in MessageTips component
- Support multilingual error messages while maintaining backward compatibility
- Clean up redundant error handling logic and simplify ErrorService
- Remove CLI --sandbox argument to avoid conflicts with directory detection
- Add explicit sandbox parameter in MCP tool calls to override Codex defaults
- Set sandboxMode: 'workspace-write' in createCodexAgent for file write permissions
- Ensure new Codex sessions can create and modify files in workspace
Remove hardcoded 'Tool Call' title from emitCodexToolCall to allow
Display components to handle their own titles using getDisplayTitle
methods with proper internationalization support.
The --sandbox parameter was causing ACP connection timeouts for gemini/qwen/iflow backends due to sandbox mode restrictions on stdin/stdout communication and file system access.
@kaizhou-lab kaizhou-lab changed the title feat: Add Codex MCP Integration and Enhanced File Services feat: Complete Codex integration with enhanced architecture and UX improvements Sep 30, 2025
@aionui
Copy link
Contributor

aionui bot commented Sep 30, 2025

🤖 Hi @goworm, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@goworm
Copy link
Contributor

goworm commented Sep 30, 2025

@gemini-cli /review is there any bugs?

@aionui
Copy link
Contributor

aionui bot commented Sep 30, 2025

🤖 Hi @goworm, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@halvee-tech halvee-tech merged commit 54a8221 into main Sep 30, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants